package com.slliver.productservice.controller;


import com.slliver.commonmodel.product.Product;
import com.slliver.productservice.service.ProductService;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.http.impl.bootstrap.HttpServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    // 根据商品id查询产品信息
    @GetMapping("/{productId}")
    public Product getProduct(@PathVariable("productId") Long productId, HttpServletRequest httpServletRequest) throws InterruptedException {
        System.out.println("有人调用商品服务； 商品id === >>> " + productId);
        System.out.println("从openfeign的请求狼机器中获取X-token的值 ==>> " + httpServletRequest.getHeader("X-token"));
        //TimeUnit.SECONDS.sleep(2);
        // int a = 100/0;
        return productService.getProductById(productId);
    }
}
